/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package web.models;

import entities.User;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

/**
 *
 * @author Jesus
 */
@ManagedBean
public class UserModel extends ListDataModel<User> implements SelectableDataModel<User> {

    public UserModel() {
    }

    public UserModel(List<User> users) {
        super(users);
    }

    @Override
    public Object getRowKey(User user) {
        return user.getEmail();
    }

    @Override
    public User getRowData(String email) {
        System.out.println("getRowData:USER --> " + email);
        if (email != null) {
            for (User user : (List<User>) getWrappedData()) {
                if (user.getEmail().equals(email)) {
                    return user;
                }
            }
        }
        return null;
    }

    public boolean add(User user) {
        return ((List<User>) getWrappedData()).add(user);
    }
}
